<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        #div1{width: 100px;height: 100px;background: rgba(0, 0, 0, .5);}
    </style>
    <script>
        window.onload = function(){
            var div1 = document.getElementById('div1');
            function randomColor(node){
                var opa = Math.random()*2;
                if(opa > 1){
                    opa = opa - 1;
                }
                node.style.background = 'rgba('+parseInt(Math.random()*256)+','+parseInt(Math.random()*256)+','+Math.floor(Math.random()*256)+','+opa+')';
            }
            div1.onclick = function(){
                randomColor(div1);
            }
        }
    </script>
</head>
<body>
    <div id="div1"></div>
</body>
</html>